package controller

import (
	"github.com/gin-gonic/gin"
	model "sdn-executor/model/snmp"
	"sdn-executor/service"
	"sdn-executor/utils/erros"
)

func ExecuteSNMPGetCmd(c *gin.Context) {
	query := model.Query{}
	if e := c.ShouldBindJSON(&query); e != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, e.Error()), nil)
		return
	}

	pdus, err := service.ExecuteSNMPGetCmd(&query)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, pdus)
}

func ExecuteSNMPGetNextCmd(c *gin.Context) {
	query := model.Query{}
	if e := c.ShouldBindJSON(&query); e != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, e.Error()), nil)
		return
	}

	pdus, err := service.ExecuteSNMPGetNextCmd(&query)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, pdus)
}

func ExecuteSNMPGetBulkCmd(c *gin.Context) {
	query := model.BulkQuery{}
	if e := c.ShouldBindJSON(&query); e != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, e.Error()), nil)
		return
	}

	pdus, err := service.ExecuteSNMPGetBulkCmd(&query)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, pdus)
}

func ExecuteSNMPBulkWalkCmd(c *gin.Context) {
	query := model.WalkQuery{}
	if e := c.ShouldBindJSON(&query); e != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, e.Error()), nil)
		return
	}

	pdus, err := service.ExecuteSNMPBulkWalkCmd(&query)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, pdus)
}

func ExecuteSNMPWalkCmd(c *gin.Context) {
	query := model.WalkQuery{}
	if e := c.ShouldBindJSON(&query); e != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, e.Error()), nil)
		return
	}

	pdus, err := service.ExecuteSNMPWalkCmd(&query)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, pdus)
}
